package leetcode.code009;


public class Solution1 implements ISolution {

	public static void main(String[] args) {

		int x = 121;
		int y = 122;
		int z = 12321;

		print(x);
		print(y);
		print(z);

	}

	public static void print(int x) {
		ISolution solution1 = new Solution1();
		boolean result = solution1.isPalindrome(x);
		System.out.println(x + " " + result);
	}

	@Override
	public boolean isPalindrome(int x) {
		if (x < 0)
			return false;
		int reverse = reverse(x);
		if (reverse == x)
			return true;
		return false;
	}

	/**
	 * leetcode.code007.Solution2 so2 = new leetcode.code007.Solution2(); int
	 * reverse = so2.reverse(x);
	 *
	 * @param x
	 * @return
	 */
	public int reverse(int x) {
		int a = 0;
		long res = 0;
		while (x != 0) {
			a = x % 10;
			x = x / 10;
			res = res * 10 + a;
		}
		if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE)
			return 0;
		return (int) res;
	}

}
